package com.we823.project.repository.dao.product;

import java.util.Date;
import java.util.List;
import java.util.Set;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.we823.project.common.web.status.TaskStatus;
import com.we823.project.model.product.ProductTaskModel;

@Repository("productTaskRepository")
public interface ProductTaskRepository extends JpaRepository<ProductTaskModel, Integer> {

	List<ProductTaskModel> findByStatusAndUserId(TaskStatus status, int userId);

	List<ProductTaskModel> findByUserIdAndStatusIn(int userId, List<TaskStatus> statusList);

	@Query("select p from ProductTaskModel p where p.status=?1 and p.userId=?2 and year(p.finishtime)=?3 and month(p.finishtime)=?4 and day(p.finishtime)=?5")
	Page<ProductTaskModel> findByStatusAndUserIdAndyFinishtime(
			TaskStatus taskStatus, int userId, int year, int month, int day,
			Pageable pageable);
	
	@Query("select p from ProductTaskModel p where p.status=?1 and p.userId=?2 and year(p.finishtime)=?3 and month(p.finishtime)=?4")
	Page<ProductTaskModel> findByStatusAndUserIdAndyFinishtime(
			TaskStatus taskStatus, int userId, int year, int month,
			Pageable pageable);

	@Query("select p from ProductTaskModel p where p.status=?1 and p.userId=?2 and year(p.finishtime)=?3")
	Page<ProductTaskModel> findByStatusAndUserIdAndyFinishtime(
			TaskStatus taskStatus, int userId, int year, Pageable pageable);

	Page<ProductTaskModel> findByStatusAndUserId(TaskStatus taskStatus,
			int userId, Pageable pageable);

	List<ProductTaskModel> findByUserIdAndStatusIn(int userId,
			List<TaskStatus> statusList, Sort sort);

	List<ProductTaskModel> findByStatusAndUserId(TaskStatus status, int userId,
			Sort sort);

	List<ProductTaskModel> findByIdIn(Set<Integer> idSet);

	Page<ProductTaskModel> findByUserId(int userId, Pageable pageable);

	@Query("select p from ProductTaskModel p where p.userId=?1 and year(p.addtime)=?2 and month(p.addtime)=?3 and day(p.addtime)=?4")
	Page<ProductTaskModel> findByUserIdAndAddtime(int userId, int year,
			int month, int day, Pageable pageable);
	@Query("select p from ProductTaskModel p where p.userId=?1 and year(p.addtime)=?2 and month(p.addtime)=?3")
	Page<ProductTaskModel> findByUserIdAndAddtime(int userId, int year,
			int month, Pageable pageable);

	@Query("select p from ProductTaskModel p where p.userId=?1 and year(p.addtime)=?2")
	Page<ProductTaskModel> findByUserIdAndAddtime(int userId, int year,
			Pageable pageable);

	List<ProductTaskModel> findByUserId(Integer userId);

	@Query("select p from ProductTaskModel p where p.userId=?1 and year(p.addtime)=?2 and month(p.addtime)=?3 and day(p.addtime)=?4")
	List<ProductTaskModel> findByUserIdAndAddtime(int userId, int year,
			int month, int day);
	@Query("select p from ProductTaskModel p where p.userId=?1 and year(p.addtime)=?2 and month(p.addtime)=?3")
	List<ProductTaskModel> findByUserIdAndAddtime(int userId, int year,
			int month);

	@Query("select p from ProductTaskModel p where p.userId=?1 and year(p.addtime)=?2")
	List<ProductTaskModel> findByUserIdAndAddtime(int userId, int year);

	List<ProductTaskModel> findByPlanDetailIdIn(List<Integer> planDetailIdList);

	ProductTaskModel findByPlanDetailId(Integer planDetailId);

	List<ProductTaskModel> findByUserIdAndAddtimeBetween(int userId,
			Date fromDate, Date endDate);

	Page<ProductTaskModel> findByUserIdAndAddtimeBetween(int userId,
			Date fromDate, Date endDate, Pageable pageable);

}
